using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DATA.ManagerObjects;
using DATA.BusinessObjects;
using DATA.Base;

namespace DATA.UnitTests
{
	[TestFixture]
    public partial class ChitietmatdosudungphongTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetChitietmatdosudungphongManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected DATA.ManagerObjects.IChitietmatdosudungphongManager manager;
		
		protected DATA.BusinessObjects.Chitietmatdosudungphong CreateNewChitietmatdosudungphong()
		{
			DATA.BusinessObjects.Chitietmatdosudungphong entity = new DATA.BusinessObjects.Chitietmatdosudungphong();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test Te";
			
			entity.SoNgayThue = 32;
			entity.TyLe = 83;
			
			using(DATA.ManagerObjects.IMatdosudungphongManager matdosudungphongManager = managerFactory.GetMatdosudungphongManager())
			    entity.Matdosudungphong = matdosudungphongManager.GetAll(1)[0];
			
			using(DATA.ManagerObjects.IPhongManager phongManager = managerFactory.GetPhongManager())
			    entity.Phong = phongManager.GetAll(1)[0];
			
			return entity;
		}
		protected DATA.BusinessObjects.Chitietmatdosudungphong GetFirstChitietmatdosudungphong()
        {
            IList<DATA.BusinessObjects.Chitietmatdosudungphong> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				DATA.BusinessObjects.Chitietmatdosudungphong entity = CreateNewChitietmatdosudungphong();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                DATA.BusinessObjects.Chitietmatdosudungphong entityA = CreateNewChitietmatdosudungphong();
				manager.Save(entityA);

                DATA.BusinessObjects.Chitietmatdosudungphong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                DATA.BusinessObjects.Chitietmatdosudungphong entityA = GetFirstChitietmatdosudungphong();
				
				entityA.SoNgayThue = 35;
				
				manager.Update(entityA);

                DATA.BusinessObjects.Chitietmatdosudungphong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.SoNgayThue, entityB.SoNgayThue);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                DATA.BusinessObjects.Chitietmatdosudungphong entity = GetFirstChitietmatdosudungphong();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

